$('#exampleModal').on('show.bs.modal', function (event) {

})
$('#create-bt').on('click', function (event) {
  $.ajax({
    type: "post",
    dataType: "json",
    url: "/post/create/"+$(this).attr("data-siteid"),
    data:{title:$("#title").val(),path:$("#path").val()},
    success: function (result) {
      if (result.code == 0) {
        $("#list").append("<p>"+result.data.title+"，<a href=\"/post/edit/"+result.data.path+"\">编辑</a></p>");
        $("#title").val("")
        $("#path").val("")
        $("#exampleModal").modal('hide')
      } else {
        alert(result.msg);
      }
    },
    error : function() {
      alert("异常！");
    }
  });
  return false;
})

if(typeof editormd!="undefined"){
  var testEditor;
  testEditor = editormd("test-editormd", {
    width   : "100%",
    height  : 640,
    syncScrolling : "single",
    path    : "/lib/"
  });
  $("#get-md-btn").bind('click', function(){
    $.ajax({
      type: "POST",//方法类型
      dataType: "json",//预期服务器返回的数据类型
      url: "/post/save" ,//url
      data: {content:testEditor.getMarkdown(),title:$("#title").val(),intro:$("#intro").val(),path:$(this).attr("data-file"),siteid:$(this).attr("data-siteid")},
      success: function (result) {
          if (result.code == 0) {
              alert("SUCCESS");
          }
      },
      error : function() {
          alert("异常！");
      }
    });
  });
}
